<template>
	<view class="page">
	</view>
</template>

<script>
	export default {
		name: '',
		data() {
			return {

			}
		},
		onload(e) {
			console.log(e)
			this.scanCode()
		},
		onshow() {
			this.scanCode()
		},
		onTabItemTap(e) {
			console.log(e);
			this.scanCode()
		},
		methods: {
			scanCode: function() {
				let _this=this;
				uni.scanCode({
					onlyFromCamera: true,
					scanType: ['qrCode'],
					autoZoom:false,
					success: function(res) {  
						if(res.result.indexOf('devnumber')==-1){
							// 不存在 devnumber 二维码不合法
							_this.$showToast({
								icon: 'loading',
								title: '二维码不合法',
								duration:2000,
							}).then(()=>{
								setTimeout(()=>{
									uni.switchTab({
										url: '/pages/index/index'
									})
								},1000)							
							})			
							
						}else{
							// let number = res.result.split('?')[1].split('=')[1];
							let arr = res.result.split('?')[1].split('&')
							let params = {},path='';
							arr.forEach(it=>{
								let n = it.split('=')
								params[n[0]] = n[1]
							})
							uni.showLoading({
								mask: true,
								title: '跳转中...'
							}) 
							
							if(params.type=='zncp'){
								path = '/package_zhinengcipan/detail/detail'
							}else{
								path = '/package_common/detail/detail'
							}
							setTimeout(()=>{
								// #ifdef MP-WEIXIN
								uni.redirectTo({
									url:`${path}?number=${params.devnumber}`,
									success() {
										uni.hideLoading();
									}						
								})
								// #endif
								
								// #ifdef APP-PLUS
								uni.navigateTo({
									url:`${path}?number=${params.devnumber}&isScan=true`,
									success() {
										uni.hideLoading();
									}						
								})
								// #endif
								
							},1000)
						}
						
					},
					fail() {  
						_this.$showToast({
							icon: 'loading',
							title: '扫码失败...',
							duration:2000,
						}).then(()=>{
							setTimeout(()=>{
								uni.switchTab({
									url: '/pages/index/index'
								})
							},1000)							
						})						
					}
				});
			}
		},
		computed: {

		},
		components: {

		},
	}
</script>

<style lang="less">
</style>
